#include <string>
#include <iostream>

class Solution {
public:
    static string compressString(string S) {
        string S1("");
        int count = 0;
        S1 += *(S.begin());
        char tmp = *(S.begin());
        for (auto ch : S)
        {
            if (tmp != ch)
            {
                tmp = ch;
                S1 += to_string(count);
                S1 += ch;
                count = 1;
            }
            else
            {
                count++;
            }
        }
        S1 += to_string(count);
        return S1.size() >= S.size() ? S : S1;
    }
};